package com.banmao.mall.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

@Component("webSessionManager")
public class AuthSessionManager extends DefaultWebSessionManager {

    @Override
    protected Serializable getSessionId(ServletRequest srequest, ServletResponse response) {

        HttpServletRequest request = (HttpServletRequest) srequest;
        String sessionId = request.getHeader("X-cskaoyan-mall-Admin-Token");
        if(sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        String sessionId2 = request.getHeader("X-Litemall-Token");
        if(sessionId2 != null && !"".equals(sessionId2)) {
            return sessionId2;
        }

        return super.getSessionId(request, response);
    }
}
